﻿using System;
using System.Net;
using System.Xml.Linq;
using System.Linq;
using System.Windows.Media;

namespace ArmoryBrowser.Entities
{
    public class Character
    {
        #region Fields
        private ModelBasePath _modelBasePathField;
        private string _battleGroupField;
        private string _charUrlField;
        private string _classField;
        private string _classIdField;
        private string _classUrlField;
        private string _factionField;
        private string _factionIdField;
        private string _genderField;
        private string _genderIdField;
        private string _guildNameField;
        private string _guildUrlField;
        private string _lastModifiedField;
        private string _levelField;
        private string _nameField;
        private string _pointsField;
        private string _prefixField;
        private string _raceField;
        private string _raceIdField;
        private string _realmField;
        private string _suffixField;
        private string _titleIdField;
        #endregion
        #region Properties
        public ModelBasePath ModelBasePath
        {
            get
            {
                return this._modelBasePathField;
            }
            set
            {
                this._modelBasePathField = value;
            }
        }

        public string BattleGroup
        {
            get
            {
                return this._battleGroupField;
            }
            set
            {
                this._battleGroupField = value;
            }
        }

        public string CharUrl
        {
            get
            {
                return this._charUrlField;
            }
            set
            {
                this._charUrlField = value;
            }
        }

        public string @Class
        {
            get
            {
                return this._classField;
            }
            set
            {
                this._classField = value;
            }
        }

        public string ClassId
        {
            get
            {
                return this._classIdField;
            }
            set
            {
                this._classIdField = value;
            }
        }

        public string ClassUrl
        {
            get
            {
                return this._classUrlField;
            }
            set
            {
                this._classUrlField = value;
            }
        }

        public string Faction
        {
            get
            {
                return this._factionField;
            }
            set
            {
                this._factionField = value;
            }
        }

        public string FactionId
        {
            get
            {
                return this._factionIdField;
            }
            set
            {
                this._factionIdField = value;
            }
        }

        public string Gender
        {
            get
            {
                return this._genderField;
            }
            set
            {
                this._genderField = value;
            }
        }

        public string GenderId
        {
            get
            {
                return this._genderIdField;
            }
            set
            {
                this._genderIdField = value;
            }
        }

        public string GuildName
        {
            get
            {
                return this._guildNameField;
            }
            set
            {
                this._guildNameField = value;
            }
        }

        public string GuildUrl
        {
            get
            {
                return this._guildUrlField;
            }
            set
            {
                this._guildUrlField = value;
            }
        }

        public string LastModified
        {
            get
            {
                return this._lastModifiedField;
            }
            set
            {
                this._lastModifiedField = value;
            }
        }

        public string Level
        {
            get
            {
                return this._levelField;
            }
            set
            {
                this._levelField = value;
            }
        }

        public string Name
        {
            get
            {
                return this._nameField;
            }
            set
            {
                this._nameField = value;
            }
        }

        public string Points
        {
            get
            {
                return this._pointsField;
            }
            set
            {
                this._pointsField = value;
            }
        }

        public string Prefix
        {
            get
            {
                return this._prefixField;
            }
            set
            {
                this._prefixField = value;
            }
        }

        public string Race
        {
            get
            {
                return this._raceField;
            }
            set
            {
                this._raceField = value;
            }
        }

        public string RaceId
        {
            get
            {
                return this._raceIdField;
            }
            set
            {
                this._raceIdField = value;
            }
        }

        public string Realm
        {
            get
            {
                return this._realmField;
            }
            set
            {
                this._realmField = value;
            }
        }

        public string Suffix
        {
            get
            {
                return this._suffixField;
            }
            set
            {
                this._suffixField = value;
            }
        }

        public string TitleId
        {
            get
            {
                return this._titleIdField;
            }
            set
            {
                this._titleIdField = value;
            }
        }

        public string PortraitUrl
        {
            get
            {
                Int32 lvl = Int32.Parse(Level);
                String lvlFolder = String.Empty;
                if (lvl == 80)
                    lvlFolder = "wow-80";
                else if (lvl >= 70 && lvl < 80)
                    lvlFolder = "wow-70";
                else
                    lvlFolder = "wow";
                return String.Format("http://armory.wow-europe.com/_images/portraits/{0}/{1}-{2}-{3}.gif", lvlFolder, GenderId, RaceId, ClassId);
            }
        }
        #endregion
        #region Constructor
        public Character(XElement element)
        {
            BattleGroup = element.GetAttributeValue("battleGroup");
            CharUrl = element.GetAttributeValue("charUrl");
            @Class = element.GetAttributeValue("class");
            ClassId = element.GetAttributeValue("classId");
            ClassUrl = element.GetAttributeValue("classUrl");
            Faction = element.GetAttributeValue("faction");
            FactionId = element.GetAttributeValue("factionId");
            Gender = element.GetAttributeValue("gender");
            GenderId = element.GetAttributeValue("genderId");
            GuildName = element.GetAttributeValue("guildName");
            GuildUrl = element.GetAttributeValue("guildUrl");
            LastModified = element.GetAttributeValue("lastModified");
            Level = element.GetAttributeValue("level");
            Name = element.GetAttributeValue("name");
            Points = element.GetAttributeValue("points");
            Prefix = element.GetAttributeValue("prefix");
            Race = element.GetAttributeValue("race");
            RaceId = element.GetAttributeValue("raceId");
            Realm = element.GetAttributeValue("realm");
            Suffix = element.GetAttributeValue("suffix");
            TitleId = element.GetAttributeValue("titleId");

            ModelBasePath = element.Elements("modelBasePath").Select(e => new ModelBasePath(e)).FirstOrDefault();
        }
        #endregion
    }
}
